package com.carl.web;

import com.carl.mapper.demo.UserDemoMapper;
import com.carl.mapper.test.UserTestMapper;
import com.carl.model.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserController {

    @Autowired
    private UserDemoMapper userDemoMapper ;

    @Autowired
    private UserTestMapper userTestMapper ;

    @RequestMapping("/listDemoUser")
    public List<UserEntity> listDemoUser() {
        List<UserEntity> users = userDemoMapper.getAll();

        return users;
    }

    @RequestMapping("/listTestUser")
    public List<UserEntity> listTestUser() {
        List<UserEntity> userList = userTestMapper.getAll();
        return userList;
    }

    @RequestMapping("/getTestUser")
    public UserEntity getUser(Long id) {
        UserEntity user = userTestMapper.getOne(id);
        return user;
    }

    @RequestMapping(value = "/saveDemoUser",method = RequestMethod.POST)
    public void save(UserEntity user) {
        userDemoMapper.insert(user);
    }

    @RequestMapping(value="updateTestUser",method = RequestMethod.POST)
    public void update(UserEntity user) {
        userTestMapper.update(user);
    }

    @RequestMapping(value="/delete/{id}/demoUser",method = RequestMethod.DELETE)
    public void delete(@PathVariable("id") Long id) {
        userDemoMapper.delete(id);
    }


}
